package com.songmy.spider.run.vo;

import java.util.Iterator;
import java.util.List;
import java.util.Map;


/***
 * 规则VO
 * @author Marc
 * @version 1.0
 */
public class SpiderRule {

	/***
	 * 域名
	 */
	private String domains = null ; 
	
	/**
	 * 扫描地址
	 */
	private List<String> urls= null ;
	
	/***
	 * 内容页地址正则
	 */
	private List<String> contentUrlReg = null ;
	
	/***
	 * 地址页地址正则
	 */
	private List<String> addUrlReg = null ;
	
	
	/***
	 * 字段属性
	 */
	private List<Field> fields = null ; 
	
	/***
	 * 请求头
	 */
	private Map<String,String> head =  null ;

	
	/****
	 * 休眠时间
	 */
	private int retryTimes = 0; 
	
	/***
	 * 沉睡时间
	 */
	private int sleepTime = 0 ; 
	
	/***
	 * 线程数
	 */
	private int thread = 1 ;
	
	/***
	 * 队列方式
	 */
	private Scheduler schedulerType = Scheduler.Queue;
	
	/***
	 * 队列使用文件的情况下,需要使用到一个文件路径,请保证文件夹,可以读写
	 */
	private String tempPath = System.getProperty("java.io.tmpdir");
	
	/***
	 * 其他队列,在使用其他队列的情况下,初始化当前类,必须要继承于Scheduler
	 */
	private String otherScheduler = null;
	
	/***
	 * 是否使用代理
	 */
	private boolean useProxy = false ; 
	
	/***
	 * 代理地址
	 */
	private String hostname = null;
	
	/***
	 * 代理端口
	 */
	private int port = 0 ;
	
	

	/**
	 * @return the callBack
	 */
	public CallBack getCallBack() {
		return callBack;
	}

	/**
	 * @param callBack the callBack to set
	 */
	public void setCallBack(CallBack callBack) {
		this.callBack = callBack;
	}

	/***
	 * 代理协议
	 */
	private String scheme_name = null ; 
	
	/***
	 * 回调方式
	 */
	private CallBack callBack = new CallBack() ;


	private List<String[]> proxyList; 
	



	/**
	 * @return the proxyList
	 */
	public List<String[]> getProxyList() {
		return proxyList;
	}

	/**
	 * @return the useProxy
	 */
	public boolean isUseProxy() {
		return useProxy;
	}

	/**
	 * @return the hostname
	 */
	public String getHostname() {
		return hostname;
	}

	/**
	 * @return the port
	 */
	public int getPort() {
		return port;
	}

	/**
	 * @return the scheme_name
	 */
	public String getScheme_name() {
		return scheme_name;
	}

	/**
	 * @param useProxy the useProxy to set
	 */
	public void setUseProxy(boolean useProxy) {
		this.useProxy = useProxy;
	}

	/**
	 * @param hostname the hostname to set
	 */
	public void setHostname(String hostname) {
		this.hostname = hostname;
	}

	/**
	 * @param port the port to set
	 */
	public void setPort(int port) {
		this.port = port;
	}

	/**
	 * @param scheme_name the scheme_name to set
	 */
	public void setScheme_name(String scheme_name) {
		this.scheme_name = scheme_name;
	}

	/**
	 * @return the tempPath
	 */
	public String getTempPath() {
		return tempPath;
	}

	/**
	 * @return the otherScheduler
	 */
	public String getOtherScheduler() {
		return otherScheduler;
	}

	/**
	 * @param tempPath the tempPath to set
	 */
	public void setTempPath(String tempPath) {
		this.tempPath = tempPath;
	}

	/**
	 * @param otherScheduler the otherScheduler to set
	 */
	public void setOtherScheduler(String otherScheduler) {
		this.otherScheduler = otherScheduler;
	}

	/**
	 * @return the thread
	 */
	public int getThread() {
		return thread;
	}

	/**
	 * @return the schedulerType
	 */
	public Scheduler getSchedulerType() {
		return schedulerType;
	}

	/**
	 * @param thread the thread to set
	 */
	public void setThread(int thread) {
		this.thread = thread;
	}

	/**
	 * @param schedulerType the schedulerType to set
	 */
	public void setSchedulerType(Scheduler schedulerType) {
		this.schedulerType = schedulerType;
	}

	/**
	 * @return the head
	 */
	public Map<String, String> getHead() {
		return head;
	}

	/**
	 * @return the retryTimes
	 */
	public int getRetryTimes() {
		return retryTimes;
	}

	/**
	 * @return the sleepTime
	 */
	public int getSleepTime() {
		return sleepTime;
	}

	/**
	 * @param retryTimes the retryTimes to set
	 */
	public void setRetryTimes(int retryTimes) {
		this.retryTimes = retryTimes;
	}

	/**
	 * @param sleepTime the sleepTime to set
	 */
	public void setSleepTime(int sleepTime) {
		this.sleepTime = sleepTime;
	}

	/**
	 * @return the domains
	 */
	public String getDomains() {
		return domains;
	}

	/**
	 * @return the urls
	 */
	public List<String> getUrls() {
		return urls;
	}

	/**
	 * @return the contentUrlReg
	 */
	public List<String> getContentUrlReg() {
		return contentUrlReg;
	}

	/**
	 * @return the addUrlReg
	 */
	public List<String> getAddUrlReg() {
		return addUrlReg;
	}

	/**
	 * @return the fields
	 */
	public List<Field> getFields() {
		return fields;
	}

	/**
	 * @return the head
	 */
	public String getHeadStr() {
		if(this.head.size() > 0 ){
			StringBuffer headStr = new StringBuffer();
			Iterator<String> ite = head.keySet().iterator();
			while (ite.hasNext()) {
				String key = ite.next();
				String value = head.get(key);
				headStr.append(key+":"+value+"\r\n");
			}
			return headStr.toString();
		}else{
			return "";
		}
	}

	/**
	 * @param domains the domains to set
	 */
	public void setDomains(String domains) {
		this.domains = domains;
	}

	/**
	 * @param urls the urls to set
	 */
	public void setUrls(List<String> urls) {
		this.urls = urls;
	}

	/**
	 * @param contentUrlReg the contentUrlReg to set
	 */
	public void setContentUrlReg(List<String> contentUrlReg) {
		this.contentUrlReg = contentUrlReg;
	}

	/**
	 * @param addUrlReg the addUrlReg to set
	 */
	public void setAddUrlReg(List<String> addUrlReg) {
		this.addUrlReg = addUrlReg;
	}

	/**
	 * @param fields the fields to set
	 */
	public void setFields(List<Field> fields) {
		this.fields = fields;
	}

	public void addheader(String key,String value){
		this.head.put(key, value);
	}

	/**
	 * @param head the head to set
	 */
	public void setHead(Map<String, String> head) {
		this.head = head;
	}


	public void setProxyList(List<String[]> proxyList) {
		this.proxyList= proxyList;
	}
	
	
	
	
	
}
